package com.example.demo.pojo;

import java.io.Serializable;

/**
 * create by Chas_tsj
 * 2024/11/1 14:47:04
 **/

public class Resp<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    public T data;
    public String msg;
    public int code;

    public Resp(T data, String msg, int code) {
        this.data = data;
        this.msg = msg;
        this.code = code;
    }

    @Override
    public String toString() {
        return "{\"code\":" + this.code + ", \"message\":\"" + this.msg + "\", \"data\":\"" + this.data + "\"" + '}';

    }

    public static void main(String[] args) {
        Resp<String> resp = new Resp<>("hello", "success", 200);
        ResultResp resultResp = new ResultResp(resp);
        System.out.println(resp.toString());
        System.out.println(resultResp.toString());
    }
}
class ThreadLocalExample {

    // 创建一个ThreadLocal变量，用于存储每个线程的名字副本
    private static final ThreadLocal<String> threadLocalName = new ThreadLocal<>();

    public static void main(String[] args) {

        // 创建两个线程
        Thread thread1 = new Thread(() -> {
            // 设置线程1的名字副本
            threadLocalName.set("Thread1 Name");
            // 获取并打印线程1的名字副本
            System.out.println("Thread1: " + threadLocalName.get());
        });

        Thread thread2 = new Thread(() -> {
            // 设置线程2的名字副本
            threadLocalName.set("Thread2 Name");
            // 获取并打印线程2的名字副本
            System.out.println("Thread2: " + threadLocalName.get());
        });

        // 启动两个线程
        thread1.start();
        thread2.start();

        // 等待两个线程执行完毕
        try {
            thread1.join();
            thread2.join();
        } catch (Exception e) {
            // 处理异常
            e.printStackTrace();
        }

        // 打印主线程的情况
        System.out.println("Main Thread: " + threadLocalName.get());
    }
}
